package com.yanqu.road.server.cmd.guess;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.CommonGuessProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.guess.CommonGuessModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = CommonGuessProto.CommonGuessReceiveRewardReqMsg.class, respMsg = CommonGuessProto.CommonGuessReceiveRewardRespMsg.class)
@Cmd(code = Protocol.S_COMMON_GUESS_RECEIVE_REWARD,desc = "通用竞猜-领取奖励")
public class CommonGuessReceiveRewardCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CommonGuessProto.CommonGuessReceiveRewardReqMsg reqMsg = CommonGuessProto.CommonGuessReceiveRewardReqMsg.parseFrom(packet.getBytes());
        try {
            player.getModule(CommonGuessModule.class).receiveReward(reqMsg);
        } catch (BusinessException e) {
            CommonGuessProto.CommonGuessReceiveRewardRespMsg.Builder respMsg = CommonGuessProto.CommonGuessReceiveRewardRespMsg.newBuilder();
            respMsg.setRet(e.getCode());
            player.sendPacket(ClientProtocol.U_COMMON_GUESS_RECEIVE_REWARD, respMsg);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
